草庐IT

Java 8 无法导入 java.util.function

全部标签

go - 如何导入本地包到主包

我尝试重构main.go,将代码分到不同的文件中。所以我将controller.go作为包Controller。但是我无法将这个本地包导入main.go。article├client├api│├main.go│└contoroller│└contoroller.go├nginx└docker-compose.yml・client:react/axios・api:golang/gin・web-server:nginx・db:mysql・container:docker・ci-tool:travis・deploy:awselasticbeanstalk主.gopackagemainimpo

go - 解释:function returns same function in go

funcmain(){gospinner(100*time.Millisecond)constn=45fibN:=fib(n)//slowfmt.Printf("\rFibonacci(%d)=%d\n",n,fibN)}funcspinner(delaytime.Duration){for{for_,r:=range`-\|/`{fmt.Printf("\r%c",r)time.Sleep(delay)}}}funcfib(xint)int{ifx能否解释一下上面的fib函数,结果是如何得到的。fib函数返回一个fib调用,最终结果是怎么来的? 最佳答案

go - 无法停止计时器

我定义了几个自动收报机,当我试图阻止它们时,我看到了下面undefined:tickerinticker.Stopundefined:Q30stickerinQ30sticker.Stop代码示例:ifactivenode(){cipaflage=truebreak}else{ifcipaflage==true{deferticker.Stop()deferQ30sticker.Stop()cipaflage=false}continue}我已经声明了代码如下ticker:=time.NewTicker(59*time.Second)Q30sticker:=time.NewTicker

go - 如何在 golang 中编写类似 throws(in java) 的代码

在Golang中有什么方法可以让函数“抛出”(就像在java中一样)错误吗?通过WhichIcanspecify,我的func可能会返回错误,调用者需要处理错误。我只是想模仿我们在Java中使用的类似“throws”的方法。可能这是非常基本的基本类型问题,对不起,我是golang的新手。注意:我已经尝试过panic、defer、recover,但问题是如果两个函数/方法都在同一个go文件中,它工作正常,但如果假设两者(调用者和func)是不同的go文件,它正在启动一个不同的go例程,调用者级别的“延迟”无法正常工作。我想这种方法也不等同于“throws”,其中函数提供者不处理错误但调用

go - http.Post 无法正常工作?

我正在尝试使用cli工具中的这段go代码访问文件上传API。帖子似乎甚至没有到达服务器,但这段代码运行没有错误,结果消息是一个空字符串。curl有效。其他帖子有效。有什么建议吗?file,err:=os.Open(c.Args().Get(0))iferr!=nil{exitErr(err)}deferfile.Close()fmt.Print("Abouttouploadfile",c.Args().Get(0),"\n");res,err:=http.Post(fmt.Sprintf("%s/upload",config.Host),"application/octet-strea

string - 无法在字符串 : "cannot use <xxx> (type <yyy>) as type string in map index" 的映射中使用基础类型的字符串

这个问题在这里已经有了答案:ConvertingacustomtypetostringinGo(4个答案)关闭3年前。我有底层字符串类型:typeCapabilitystring。我想将它用作字符串映射中的字符串,但出现错误:cannotusecap(typeCapability)astypestringinmapindex这是我的代码:packagemainimport("fmt")typeCapabilitystringvarcaps_list=map[string]int{"HOME":1,}funcmain(){varcapCapability//stringcap="HOME

go - 我无法安装 go 包

我目前正在尝试安装https://github.com/willnorris/imageproxy.我是golang的新手。所以我先安装了go,github和hg。我尝试了一些东西,克隆git存储库,使用goget,使用goinstall,gobuild。但没有任何效果,它可以将文件下载到src目录,但没有得到bin。那么有人有想法吗?---编辑---和:去获取github.com/willnorris/imageproxy/cmd/imageproxy我得到:[root@s17848415go]#gogetgithub.com/willnorris/imageproxy/cmd/im

go - 无法将 time.Now() 转换为字符串

我有这个结构://NearbywhatevertypeNearbystruct{idint`json:"id,omitempty"`meint`json:"me,omitempty"`youint`json:"you,omitempty"`contactTimestring`json:"contactTime,omitempty"`}然后我称之为:strconv.Itoa(time.Now())像这样:s1:=Nearby{id:1,me:1,you:2,contactTime:strconv.Itoa(time.Now())}但是它说:>cannotusetime.Now()(typ

go - 如何避免 VSCode 在 Golang 中删除未使用的 var 或导入

这个问题在这里已经有了答案:Howtoavoidannoyingerror"declaredandnotused"(8个答案)HowtodisableGolangunusedimporterror(8个答案)关闭3年前。我正在使用最新的VSCode、golang插件和最新的golang版本学习golang。Goland不会让你有未使用的东西-例如变量和导入。VSCode有办法绕过它吗?谢谢你:)

go - 即使在设置结构标签后也无法解析 TOML 文件

我使用以下方式安装了依赖项:gogetgithub.com/BurntSushi/toml我在与main.go相同的文件夹中创建了一个toml文件:.|--cloud.toml`--main.go云.toml[database]host="localhost"port=8086secure=falseusername="test"password="password"dbName="test"main.gopackagemainimport("fmt""github.com/BurntSushi/toml")typetomlConfigstruct{DBdbInfo}typedbInf